package com.itheima;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * @auther Macrydy
 * @date 2020/7/12 10:14
 */
public class NIOClient {
    public static void main(String[] args) throws IOException {
        //1.打开通道
        SocketChannel socketChannel = SocketChannel.open();

        //2.指定IP和端口号
        socketChannel.connect(new InetSocketAddress("127.0.0.1", 10010));

        //3.写出数据
        ByteBuffer wrap = ByteBuffer.wrap("来了老弟".getBytes());
        socketChannel.write(wrap);

        //4.释放资源
        socketChannel.close();
    }
}
